﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;

namespace PPIDesktopClient.General
{
    public class DownloadImageProcess
    {
        #region Events
        
        public event EventHandler FinishDownloadImage;
        private void OnFinishDownloadImage(object o, EventArgs e)
        {
            // Safely invoke an event:
            if (FinishDownloadImage != null)
            {
                FinishDownloadImage(o, e);
            }
        }

        void m_DownloadFile_FinishDownloadFile(object sender, EventArgs e)
        {
            m_IsDownloading = false;
            OnFinishDownloadImage(this, e);
        }
        
        #endregion

        #region Private Fields
        
        private EBaseImage m_ImageToDownload;
        private DownloadFile m_DownloadFile;
        private bool m_IsDownloading;

        #endregion

        #region Properties
        
        public bool IsDownloading
        {
            get { return m_IsDownloading; }
        }
        
        #endregion

        public DownloadImageProcess()
        {
            m_DownloadFile = new DownloadFile();
            m_DownloadFile.FinishDownloadFile += new EventHandler(m_DownloadFile_FinishDownloadFile);
        }

        public void StartDownload(EBaseImage image)
        {
            m_DownloadFile.SetUrl(image.GetWebFileUrl());
            m_DownloadFile.SetFileDestination(image.GetLocalPath().FullName);
            m_DownloadFile.StartDownload();
            m_IsDownloading = true;
        }

        

    }
}
